<?php
namespace V1\Controller;
/**
 * @desc 活动控制器
 * 
 * @author wangzhenxian <zendwang@qq.com>
 */

class ActivitesController extends BaseController {
    
     protected $errorCode = array(
        'index' => array(
            '-10'=>'无相关数据',
        ),
        'recommend' => array(
            '-10'=>'无相关数据',
        ),
        'detail' => array(
            '-10'=>'无相关数据',
        ),
    );
     /**
     * 活动列表
     */
    public function index(){
       $data = array("code" => 0,"msg" => "","info"=>array());
       
       $pageIndex = I('p',1,'intval');
       $pageSize = I('r',5,'intval');
       
       $list =M('Activites')->page($pageIndex,$pageSize)->field($field)->cache(true,60)->select();
       empty($list) && $this->responseError(-10);
       
       foreach ($list as  $key=>$value) {
           if($value['deadline']<NOW_TIME) $list[$key]['status']='已过期';
           else $list[$key]['status']='进行中';
           if(!empty($value['path'])) $list[$key]['path'] = str_replace('/Uploads','', $value['path']);
       }
       $data['info'] = $list;
       $this->responseResult($data);
    }
    /**
     * 首页推荐活动
     */
    public function recommend(){
       $data = array("code" => 0,"msg" => "","info"=>array());
       
       $list = M('Activites')->where('deadline>'.NOW_TIME)->limit(3)->cache(true,60)->select();
       empty($list) && $this->responseError(-10);
       
       $data['info'] = $list;
       $this->responseResult($data); 
    }
    /**
     * 活动详情
     */
    public function detail(){
       $data = array("code" => 0,"msg" => "","info"=>array());  
       $result = $this->find('ActivitesDetail');
       empty($result) && $this->responseError(-10);
       $data['info']=$result[0];
       $this->responseResult($data);
    }
}